let app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
       this.setData({
        optionData:options
       })
       var that=this
    wx.request({
        url: app.globalData.siteroot,
        data: {
          do:'Customer_customerInfo',
          cus_id:options.cus_id,
          user_id:options.user_id,
          staff_id:wx.getStorageSync('staff_bind_id')
        },
        success: function(res) {
           that.setData({
            info:res.data.info
           })
        }
      })
  },
  save:function(){
    var that=this
    wx.request({
      url: app.globalData.siteroot,
       data: {
         do:'Message_getPushTmplIds',
         temp_name:'leave_message,place_order,visit_message'
      },
     success: function(res) {
        var leave_message=res.data.info.leave_message
        wx.requestSubscribeMessage({
            tmplIds: [leave_message],
            success (res) {
                wx.request({
                    url: app.globalData.siteroot,
                     data: {
                       do:'Member_subscribeTimes',
                       subscribe_data:[{"leave_message":1},{"place_order":0},{"visit_message":0}],
                       staff_id:wx.getStorageSync('staff_bind_id')
                    },
                   success: function(res) {
                    wx.request({
                      url: app.globalData.siteroot,
                       data: {
                         do:'Customer_editCustomer',
                         phone: that.data.info.phone,
                         wx_num: that.data.info.wx_num,
                         email: that.data.info.email,
                         position: that.data.info.position ,
                         company_name: that.data.info.company_name,
                         gender:that.data.info.gender,
                         birthday: that.data.info.birthday,
                         address: that.data.info.address,
                         cus_id:that.data.optionData.cus_id,
                         user_id:that.data.optionData.user_id,
                         staff_id:wx.getStorageSync('staff_bind_id')
                      },
                     success: function(res) {
                         wx.navigateBack({
                             delta:1,
                             success: function() {
                              
                             }
                          })
                     }
                    })
                   }
                  })
            }
        })
     }
    })
  },
  email:function(e){
    if(typeof(e.detail.value)!='undefined')
    {
      var info=this.data.info
      info['email']=e.detail.value
      this.setData({
         info:info
      })
    }
  },
  wx_num:function(e){
    if(typeof(e.detail.value)!='undefined')
    {
      var info=this.data.info
      info['wx_num']=e.detail.value
      this.setData({
         info:info
      })
    }
  },
  address:function(e){
    if(typeof(e.detail.value)!='undefined')
    {
      var info=this.data.info
      info['address']=e.detail.value
      this.setData({
         info:info
      })
    }
  },
  birthday:function(e){
    if(typeof(e.detail.value)!='undefined')
    {
      var info=this.data.info
      info['birthday']=e.detail.value
      this.setData({
         info:info
      })
    }
  },
  position:function(e){
    if(typeof(e.detail.value)!='undefined')
    {
      var info=this.data.info
      info['position']=e.detail.value
      this.setData({
         info:info
      })
    }
  },
  company_name:function(e){
    if(typeof(e.detail.value)!='undefined')
    {
      var info=this.data.info
      info['company_name']=e.detail.value
      this.setData({
         info:info
      })
    }
  },
  choosemale:function(){
    var info=this.data.info
    info['gender']=1
    this.setData({
      info:info
    })
  },
  choosefemale:function(){
    var info=this.data.info
    info['gender']=2
    this.setData({
      info:info
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})